package com.xk.meeting.dao;

import com.sun.org.apache.regexp.internal.RE;
import com.xk.meeting.entity.Regform;
import com.xk.meeting.entityutils.RegformList;
import com.xk.meeting.utils.ConnectionUtils;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;

import java.util.List;

public class RegformDaoImpl implements RegformDao{
    private JdbcTemplate template = new JdbcTemplate(ConnectionUtils.getDataSource());
    @Override
    public int addRegform(Regform regform) {
        String sql = "insert into regform values(null,?,?,?,?,?,?,?,?,?,?,?)";
        return template.update(sql,regform.getUid(),regform.getTeamname(),regform.getTeampeo(),regform.getUnit(),
                regform.getEmpnum(),regform.getAddress(),regform.getPhone(),regform.getTelnum(),
                regform.getEmail(),regform.getPurpose(),regform.getRemarks());
    }

    @Override
    public int isExist(int uid) {
        String sql = "select count(uid) from regform where uid = ?";
        return template.queryForObject(sql,Integer.class,uid);
    }

    @Override
    public List<Regform> getRegforms(int index,int rows) {
        String sql = "select * from regform limit ?,?";
        return template.query(sql,new BeanPropertyRowMapper<Regform>(Regform.class),index,rows);
    }

    @Override
    public Regform getRegform(int uid) {
        String sql = "select * from regform where uid = ?";
        return template.queryForObject(sql,new BeanPropertyRowMapper<Regform>(Regform.class),uid);
    }

    @Override
    public int getCount() {
        String sql = "select count(id) from regform";
        return template.queryForObject(sql,Integer.class);
    }
}
